import java.lang.reflect.Array;
import java.util.Arrays;

public class Treehet {
       public int [] elme;
       public int usesize;
    public Treehet(){
        this.elme=new int[10];
    }
    public void sethet(int [] num){
        for (int i=0;i< num.length;i++){
            this.elme[i]=num[i];
            usesize++;
        }
    }
    public void  getdat(){
        for (int parent=(usesize-1)/2;parent>=0;parent--){
              int child=(parent*2)+1;//代表左孩子
              while (child<usesize){
                  if(child+1<usesize&&elme[child]<elme[child+1]){
                      //直接保持有右的时候右大
                      child++;
                  }
                  if(elme[parent]<elme[child]){
                      jiaoh(elme,parent,child);
                      parent=child;
                      child=parent*2+1;
                  }
                  else{
                      break;
                  }
              }
        }
    }
     public void poll(){
        if(ifkon(usesize)){
            return;
        }
        else{
            jiaoh(elme,0,usesize-1);
            usesize--;
            getdat();
        }
     }


     public boolean ifkon(int usesize){
        if(usesize==0){
            return  true;
        }
        else return false;
    }
//    public int add(int val){
//        if(iffull()){
//            Arrays.copyOf(elme, elme.length*2);
//        }
//        else{
//            usesize++;
//            elme[usesize-1]=val;
//        }
//    }
    public boolean iffull(){
        if(elme.length==usesize){
            return true;
        }
        else return false;
    }
    @Override
    public String toString() {
        return "Treehet{" +
                "elme=" + Arrays.toString(elme) +
                ", usesize=" + usesize +
                '}';
    }

    public void jiaoh(int[] elme, int ret1, int ret2){
        int temp=elme[ret1];
        elme[ret1]=elme[ret2];
        elme[ret2]=temp;
    }

    public static void main(String[] args) {
        Treehet treehet=new Treehet();
        int []arr={27,15,19,18,28,34,65,49,25,37};
        treehet.sethet(arr);
        treehet.getdat();
        treehet.poll();
        System.out.println(treehet.toString());
    }
}
